<template>
  <div class="departments-page">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="container">
        <h1 class="page-title">科室导航</h1>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/portal' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>科室导航</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    
    <div class="container main-content">
      <!-- 搜索栏 -->
      <div class="search-bar">
        <el-input
          v-model="searchKeyword"
          placeholder="请输入科室名称或相关疾病关键词"
          class="search-input"
          clearable
          @keyup.enter="searchDepartments"
        >
          <template #append>
            <el-button type="primary" @click="searchDepartments">
              <el-icon><Search /></el-icon>
              搜索
            </el-button>
          </template>
        </el-input>
        
        <div class="hot-keywords">
          <span class="hot-label">热门搜索：</span>
          <el-tag
            v-for="tag in hotTags"
            :key="tag"
            effect="plain"
            class="hot-tag"
            @click="searchKeyword = tag; searchDepartments();"
          >
            {{ tag }}
          </el-tag>
        </div>
      </div>
      
      <!-- 科室导航内容 -->
      <div class="departments-content">
        <el-tabs v-model="activeCategory" class="department-tabs">
          <el-tab-pane label="全部科室" name="all">
            <div class="all-departments">
              <div class="department-category" v-for="category in departmentCategories" :key="category.type">
                <h3 class="category-title">{{ category.name }}</h3>
                <div class="department-list">
                  <div
                    class="department-item"
                    v-for="dept in category.departments"
                    :key="dept.id"
                    @click="navigateToDepartment(dept.id)"
                  >
                    {{ dept.name }}
                  </div>
                </div>
              </div>
            </div>
          </el-tab-pane>
          
          <el-tab-pane label="内科" name="internal">
            <div class="department-list large-list">
              <div
                class="department-item large-item"
                v-for="dept in internalDepartments"
                :key="dept.id"
                @click="navigateToDepartment(dept.id)"
              >
                <div class="department-icon">
                  <el-icon><FirstAidKit /></el-icon>
                </div>
                <div class="department-info">
                  <h3 class="department-name">{{ dept.name }}</h3>
                  <p class="department-desc">{{ dept.description }}</p>
                </div>
              </div>
            </div>
          </el-tab-pane>
          
          <el-tab-pane label="外科" name="surgery">
            <div class="department-list large-list">
              <div
                class="department-item large-item"
                v-for="dept in surgeryDepartments"
                :key="dept.id"
                @click="navigateToDepartment(dept.id)"
              >
                <div class="department-icon">
                  <el-icon><Scissors /></el-icon>
                </div>
                <div class="department-info">
                  <h3 class="department-name">{{ dept.name }}</h3>
                  <p class="department-desc">{{ dept.description }}</p>
                </div>
              </div>
            </div>
          </el-tab-pane>
          
          <el-tab-pane label="专科" name="special">
            <div class="department-list large-list">
              <div
                class="department-item large-item"
                v-for="dept in specialDepartments"
                :key="dept.id"
                @click="navigateToDepartment(dept.id)"
              >
                <div class="department-icon">
                  <el-icon><View /></el-icon>
                </div>
                <div class="department-info">
                  <h3 class="department-name">{{ dept.name }}</h3>
                  <p class="department-desc">{{ dept.description }}</p>
                </div>
              </div>
            </div>
          </el-tab-pane>
          
          <el-tab-pane label="医技科室" name="technical">
            <div class="department-list large-list">
              <div
                class="department-item large-item"
                v-for="dept in technicalDepartments"
                :key="dept.id"
                @click="navigateToDepartment(dept.id)"
              >
                <div class="department-icon">
                  <el-icon><Monitor /></el-icon>
                </div>
                <div class="department-info">
                  <h3 class="department-name">{{ dept.name }}</h3>
                  <p class="department-desc">{{ dept.description }}</p>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      
      <!-- 常见疾病 -->
      <div class="common-diseases">
        <h2 class="section-title">常见疾病导航</h2>
        <div class="disease-categories">
          <div class="disease-category" v-for="(diseases, organ) in commonDiseases" :key="organ">
            <h3 class="disease-category-title">{{ organ }}</h3>
            <div class="disease-tags">
              <el-tag
                v-for="disease in diseases"
                :key="disease.name"
                type="info"
                effect="plain"
                class="disease-tag"
                @click="searchByDisease(disease.name)"
              >
                {{ disease.name }}
              </el-tag>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const searchKeyword = ref('')
const activeCategory = ref('all')

// 热门搜索标签
const hotTags = ['心脏病', '糖尿病', '骨科', '肿瘤', '妇产科', '儿科', '神经内科']

// 科室分类数据
const departmentCategories = [
  {
    type: 'internal',
    name: '内科',
    departments: [
      { id: 1, name: '心血管内科' },
      { id: 2, name: '消化内科' },
      { id: 3, name: '呼吸内科' },
      { id: 4, name: '神经内科' },
      { id: 5, name: '内分泌科' },
      { id: 6, name: '肾内科' },
      { id: 7, name: '血液科' },
      { id: 8, name: '风湿免疫科' }
    ]
  },
  {
    type: 'surgery',
    name: '外科',
    departments: [
      { id: 9, name: '普通外科' },
      { id: 10, name: '骨科' },
      { id: 11, name: '胸外科' },
      { id: 12, name: '神经外科' },
      { id: 13, name: '心脏外科' },
      { id: 14, name: '整形外科' },
      { id: 15, name: '泌尿外科' },
      { id: 16, name: '肝胆外科' }
    ]
  },
  {
    type: 'special',
    name: '专科',
    departments: [
      { id: 17, name: '眼科' },
      { id: 18, name: '耳鼻喉科' },
      { id: 19, name: '口腔科' },
      { id: 20, name: '皮肤科' },
      { id: 21, name: '妇产科' },
      { id: 22, name: '儿科' },
      { id: 23, name: '精神心理科' },
      { id: 24, name: '中医科' }
    ]
  },
  {
    type: 'technical',
    name: '医技科室',
    departments: [
      { id: 25, name: '检验科' },
      { id: 26, name: '放射科' },
      { id: 27, name: '超声科' },
      { id: 28, name: '病理科' },
      { id: 29, name: '麻醉科' },
      { id: 30, name: '输血科' },
      { id: 31, name: '药剂科' },
      { id: 32, name: '营养科' }
    ]
  }
]

// 各分类科室的详细信息
const internalDepartments = [
  { id: 1, name: '心血管内科', description: '主要诊治各种心血管疾病，如冠心病、高血压、心力衰竭、心律失常等' },
  { id: 2, name: '消化内科', description: '专注于食管、胃、肠、肝、胆、胰等消化系统疾病的诊断与治疗' },
  { id: 3, name: '呼吸内科', description: '治疗支气管炎、肺炎、哮喘、慢性阻塞性肺病、肺癌等呼吸系统疾病' },
  { id: 4, name: '神经内科', description: '处理神经系统疾病，如头痛、脑血管病、帕金森病、癫痫等' },
  { id: 5, name: '内分泌科', description: '诊治甲状腺疾病、糖尿病、肥胖症等代谢和内分泌系统疾病' },
  { id: 6, name: '肾内科', description: '负责肾小球肾炎、肾病综合征、尿路感染等肾脏疾病的治疗' },
  { id: 7, name: '血液科', description: '专治白血病、贫血、血小板减少症等血液系统疾病' },
  { id: 8, name: '风湿免疫科', description: '处理类风湿关节炎、系统性红斑狼疮等自身免疫性疾病' }
]

const surgeryDepartments = [
  { id: 9, name: '普通外科', description: '进行各类常见外科手术，如疝气、阑尾炎、胆囊切除等' },
  { id: 10, name: '骨科', description: '治疗骨折、关节疾病、脊柱疾病和运动损伤等' },
  { id: 11, name: '胸外科', description: '专注于肺部、食管、纵隔等胸腔内脏器官的手术治疗' },
  { id: 12, name: '神经外科', description: '处理脑部和脊髓的外科疾病，如脑肿瘤、颅内出血等' },
  { id: 13, name: '心脏外科', description: '实施心脏瓣膜置换、冠状动脉搭桥等心脏手术' },
  { id: 14, name: '整形外科', description: '进行面部及身体其他部位的整形和重建手术' },
  { id: 15, name: '泌尿外科', description: '治疗肾脏、输尿管、膀胱和前列腺等泌尿系统疾病' },
  { id: 16, name: '肝胆外科', description: '专注于肝脏、胆囊、胰腺等器官的外科治疗' }
]

const specialDepartments = [
  { id: 17, name: '眼科', description: '治疗各种眼部疾病，如白内障、青光眼、视网膜病变等' },
  { id: 18, name: '耳鼻喉科', description: '处理耳、鼻、喉和头颈部疾病，如中耳炎、鼻窦炎等' },
  { id: 19, name: '口腔科', description: '提供牙齿、口腔黏膜和颌面部疾病的诊疗服务' },
  { id: 20, name: '皮肤科', description: '诊治各种皮肤病，如湿疹、银屑病、痤疮等' },
  { id: 21, name: '妇产科', description: '提供妇科疾病治疗、孕期保健和分娩服务' },
  { id: 22, name: '儿科', description: '专门为儿童提供医疗服务，涵盖儿童常见疾病的诊治' },
  { id: 23, name: '精神心理科', description: '处理抑郁症、焦虑症等心理和精神疾病' },
  { id: 24, name: '中医科', description: '运用中医理论和方法诊治各类疾病' }
]

const technicalDepartments = [
  { id: 25, name: '检验科', description: '进行血液、尿液等各类检验，为临床诊断提供依据' },
  { id: 26, name: '放射科', description: '通过X光、CT、MRI等设备进行影像学检查' },
  { id: 27, name: '超声科', description: '利用超声波进行无创性检查，如心脏、腹部超声等' },
  { id: 28, name: '病理科', description: '分析组织样本，确定疾病的性质和程度' },
  { id: 29, name: '麻醉科', description: '负责手术和各种有创性操作的麻醉管理' },
  { id: 30, name: '输血科', description: '管理血库并进行输血相关工作' },
  { id: 31, name: '药剂科', description: '负责药品管理、调配和临床用药指导' },
  { id: 32, name: '营养科', description: '提供膳食营养评估和治疗性饮食指导' }
]

// 常见疾病导航
const commonDiseases = {
  '心脑血管': [
    { name: '高血压', departmentId: 1 },
    { name: '冠心病', departmentId: 1 },
    { name: '脑卒中', departmentId: 4 },
    { name: '心力衰竭', departmentId: 1 }
  ],
  '消化系统': [
    { name: '胃炎', departmentId: 2 },
    { name: '胃溃疡', departmentId: 2 },
    { name: '肝炎', departmentId: 2 },
    { name: '胆囊炎', departmentId: 16 }
  ],
  '呼吸系统': [
    { name: '肺炎', departmentId: 3 },
    { name: '哮喘', departmentId: 3 },
    { name: '慢性支气管炎', departmentId: 3 },
    { name: '肺癌', departmentId: 3 }
  ],
  '骨科疾病': [
    { name: '骨折', departmentId: 10 },
    { name: '关节炎', departmentId: 10 },
    { name: '腰椎间盘突出', departmentId: 10 },
    { name: '颈椎病', departmentId: 10 }
  ],
  '内分泌系统': [
    { name: '糖尿病', departmentId: 5 },
    { name: '甲状腺疾病', departmentId: 5 },
    { name: '痛风', departmentId: 5 }
  ]
}

// 搜索科室
const searchDepartments = () => {
  if (!searchKeyword.value) return
  
  console.log('搜索关键词:', searchKeyword.value)
  // 实际项目中这里应该进行搜索逻辑处理
  // 可以跳转到搜索结果页面或者在当前页面过滤显示
}

// 根据疾病搜索
const searchByDisease = (diseaseName) => {
  searchKeyword.value = diseaseName
  searchDepartments()
}

// 导航到科室详情页
const navigateToDepartment = (departmentId) => {
  router.push(`/portal/department/${departmentId}`)
}
</script>

<style scoped>
.departments-page {
  background-color: #f5f7fa;
  min-height: 100vh;
  padding-bottom: 40px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-header {
  background-color: white;
  padding: 20px 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-bottom: 30px;
}

.page-title {
  font-size: 24px;
  color: #333;
  margin: 0 0 10px;
}

.main-content {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 30px;
  margin-bottom: 30px;
}

.search-bar {
  margin-bottom: 30px;
}

.search-input {
  width: 100%;
}

.hot-keywords {
  margin-top: 15px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.hot-label {
  color: #909399;
  margin-right: 10px;
}

.hot-tag {
  margin: 5px 10px 5px 0;
  cursor: pointer;
}

.departments-content {
  margin-bottom: 40px;
}

.all-departments {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.department-category {
  margin-bottom: 10px;
}

.category-title {
  font-size: 18px;
  margin: 0 0 15px;
  padding-left: 15px;
  border-left: 4px solid #1989fa;
}

.department-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.department-item {
  background: #f7f7f7;
  padding: 15px;
  border-radius: 5px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.department-item:hover {
  background: #e6f1fc;
  color: #1989fa;
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.large-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.large-item {
  display: flex;
  align-items: center;
  background: #f9f9f9;
  padding: 20px;
  border-radius: 8px;
  text-align: left;
}

.department-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #1989fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
}

.department-icon .el-icon {
  font-size: 30px;
  color: white;
}

.department-info {
  flex: 1;
}

.department-name {
  font-size: 18px;
  margin: 0 0 10px;
  color: #333;
}

.department-desc {
  color: #666;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.section-title {
  font-size: 22px;
  margin: 0 0 20px;
  position: relative;
  padding-left: 15px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 20px;
  background-color: #1989fa;
  border-radius: 3px;
}

.disease-categories {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.disease-category-title {
  font-size: 16px;
  margin: 0 0 15px;
  color: #606266;
  position: relative;
  padding-left: 12px;
}

.disease-category-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 14px;
  background-color: #1989fa;
  border-radius: 2px;
}

.disease-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.disease-tag {
  cursor: pointer;
}

.disease-tag:hover {
  color: #1989fa;
  border-color: #1989fa;
}

@media (max-width: 992px) {
  .department-list {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .large-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .department-list {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .department-icon {
    width: 50px;
    height: 50px;
  }
  
  .department-icon .el-icon {
    font-size: 24px;
  }
}

@media (max-width: 576px) {
  .department-list {
    grid-template-columns: 1fr;
  }
  
  .main-content {
    padding: 20px;
  }
}
</style> 